package com.masterclient.app.modules.shop.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.shop.DealerShippingDetailItemBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.R;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

/**
 * @auther hjian
 * @date 2020/9/12.
 */
public class DealerShippingDetailAdapter extends BaseQuickAdapter<DealerShippingDetailItemBean, BaseViewHolder> {

    private String delivery_type;

    public void setDelivery_type(String delivery_type) {
        this.delivery_type = delivery_type;
    }

    public DealerShippingDetailAdapter() {
        super(R.layout.item_dealer_shipping_detail);
    }

    @Override
    protected void convert(BaseViewHolder helper, DealerShippingDetailItemBean item) {

        TagFlowLayout flowLayout = helper.getView(R.id.item_shipping_detail_address);
        flowLayout.setAdapter(new TagAdapter<String>(item.getArea_desc()) {
            public View getView(FlowLayout parent, int position, String bean) {
                TextView tv = (TextView) mLayoutInflater.inflate(R.layout.item_dealer_shipping_text,
                        flowLayout, false);
                ViewGroup.MarginLayoutParams param = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                param.setMargins(ScreenUtils.dp2px(5), ScreenUtils.dp2px(12),ScreenUtils.dp2px(5),0);
                tv.setLayoutParams(param);
                tv.setText(bean);
                return tv;
            }
        });

        View freeLayout = helper.getView(R.id.item_shipping_detail_free_layout);
        ImageView free = helper.getView(R.id.item_shipping_detail_free);
        ImageView nofree = helper.getView(R.id.item_shipping_detail_nofree);


        if ("1".equals(item.getIs_free())){
            freeLayout.setVisibility(View.GONE);
            free.setImageResource(R.mipmap.dealer_radio_selected);
            nofree.setImageResource(R.mipmap.dealer_radio_unselecte);
        }else {
            freeLayout.setVisibility(View.VISIBLE);
            free.setImageResource(R.mipmap.dealer_radio_unselecte);
            nofree.setImageResource(R.mipmap.dealer_radio_selected);
            helper.setText(R.id.item_shipping_detail_first_num, item.getFirst_weight())
                    .setText(R.id.item_shipping_detail_second_num, item.getSecond_weight())
                    .setText(R.id.item_shipping_detail_first_price, item.getFirst_price())
                    .setText(R.id.item_shipping_detail_second_price, item.getSecond_price())
                    .setText(R.id.item_shipping_detail_first_unit, "0".equals(delivery_type)?"kg":"件")
                    .setText(R.id.item_shipping_detail_second_unit, "0".equals(delivery_type)?"kg":"件");
        }





    }
}
